<?php
require_once WACT_ROOT . 'view/view.inc.php';
require_once WACT_ROOT . 'controller/controller.inc.php';
require_once WACT_ROOT . 'controller/form.inc.php';

require_once WACT_ROOT . 'validation/rules/match.inc.php';
require_once WACT_ROOT . 'validation/rules/member.inc.php';
require_once WACT_ROOT . 'validation/rules/pattern.inc.php';

require_once WACT_ROOT . 'util/dataspace.inc.php';

require_once APP_ROOT . "model/common/session.php";
require_once APP_ROOT . "model/common/state.php";
require_once APP_ROOT . "model/common/user.php";
require_once APP_ROOT . "model/common/player.php";
require_once APP_ROOT . "model/common/payment.php";
require_once APP_ROOT . "model/common/subscription.php";
require_once APP_ROOT . "view/pub/myprofile.view.php";
require_once APP_ROOT . "model/common/site.php";


class MyprofilePlayerprofilePage extends PageController {
	function MyprofilePlayerprofilePage() {
		parent::PageController();

		$Form=new FormController();
		$Form->addChild('getlist', new ButtonController(new Delegate($this, 'getlist')));

		$this->addChild('myprofile_form',$Form);
		$this->setDefaultChild('myprofile_form');

		$Form->addRule(new RequiredRule('filters'));
		$Form->addRule(new MemberRule('filters',array_flip(array('all', 'filtered'))));

        $mytemplate1 = 'pub/myprofile/message.html';

        $mytemplate2 = 'pub/myprofile/layout.itemlist.html';

        $mytemplate3 = 'pub/myprofile/notlogin.html';

		$this->addView('messagepage',new MyprofileView($mytemplate1,2));
		if(Session::isLogin())
			$this->setDefaultView(new MyprofileView($mytemplate2,4));
		else
			$this->setDefaultView(new MyprofileView($mytemplate3,0));

	}

	function getlist(&$controller, &$request, &$responseModel){
		if($responseModel->isValid()){
			$responseModel->set('page',1);
			Session::saveResponseModel($responseModel,'filter.myplayers');
		}
	}
}

class MyprofileTeamprofilePage extends PageController {
	function MyprofileTeamprofilePage(){
		parent::PageController();

		$Form=new FormController();
		$Form->addChild('getteamlist', new ButtonController(new Delegate($this, 'getlist')));

		$this->addChild('myprofile_form',$Form);
		$this->setDefaultChild('myprofile_form');

	//	$Form->addRule(new RequiredRule('filters'));
	//	$Form->addRule(new MemberRule('filters',array_flip(array('teamall', 'teamfiltered'))));


        $mytemplate1 = 'pub/myprofile/message.html';

        $mytemplate2 = 'pub/myprofile/layout.itemlist.html';

        $mytemplate3 = 'pub/myprofile/notlogin.html';

        $this->addView('messagepage',new MyprofileView($mytemplate1,2));
		if(Session::isLogin())
			$this->setDefaultView(new MyprofileView($mytemplate2,5));
		else
			$this->setDefaultView(new MyprofileView($mytemplate3,0));

	}

	function getlist(&$controller, &$request, &$responseModel){
		if($responseModel->isValid()){
			$responseModel->set('page',1);
			Session::saveResponseModel($responseModel,'filter.myteams');
		}
	}
}

class MyprofileLeagueprofilePage extends PageController {
	function MyprofileLeagueprofilePage(){
		parent::PageController();

		$Form=new FormController();
		$Form->addChild('getleaglist', new ButtonController(new Delegate($this, 'getlist')));

		$this->addChild('myprofile_form',$Form);
		$this->setDefaultChild('myprofile_form');


        $mytemplate1 = 'pub/myprofile/message.html';

        $mytemplate2 = 'pub/myprofile/layout.itemlist.html';

        $mytemplate3 = 'pub/myprofile/notlogin.html';

		$this->addView('messagepage',new MyprofileView($mytemplate1,2));
		if(Session::isLogin())
			$this->setDefaultView(new MyprofileView($mytemplate2,6));
		else
			$this->setDefaultView(new MyprofileView($mytemplate3,0));

	}

	function getlist(&$controller, &$request, &$responseModel){
		if($responseModel->isValid()){
			$responseModel->set('page',1);
			Session::saveResponseModel($responseModel,'filter.myleagues');
		}
	}
}

class MyprofileEventsPage extends PageController {
	function MyprofileEventsPage(){
		parent::PageController();

		$Form=new FormController();

		$this->addChild('myprofile_form',$Form);
		$this->setDefaultChild('myprofile_form');


        $mytemplate1 = 'pub/myprofile/message.html';

        $mytemplate2 = 'pub/myprofile/layout.itemlist.html';

        $mytemplate3 = 'pub/myprofile/notlogin.html';

        $this->addView('messagepage',new MyprofileView($mytemplate1,2));
		if(Session::isLogin())
			$this->setDefaultView(new MyprofileView($mytemplate2,7));
		else
			$this->setDefaultView(new MyprofileView($mytemplate3,0));

	}

}

class MyprofileArticlesPage extends PageController {
	function MyprofilearticlesPage(){
		parent::PageController();

		$Form=new FormController();
		$Form->addChild('getartlist', new ButtonController(new Delegate($this, 'getlist')));

		$this->addChild('myprofile_form',$Form);
		$this->setDefaultChild('myprofile_form');

        $mytemplate1 = 'pub/myprofile/message.html';

        $mytemplate2 = 'pub/myprofile/layout.itemlist.html';

        $mytemplate3 = 'pub/myprofile/notlogin.html';

		$this->addView('messagepage',new MyprofileView($mytemplate1,2));
		if(Session::isLogin())
			$this->setDefaultView(new MyprofileView($mytemplate2,8));
		else
			$this->setDefaultView(new MyprofileView($mytemplate3,0));

	}

	function getlist(&$controller, &$request,&$responseModel){

		$responseModel->set('page',1);
		Session::saveResponseModel($responseModel,'filter.myarticles');

	}

}

class MyprofileDeleteitemPage extends PageController {
	function MyprofileDeleteitemPage(){
		parent::PageController();

		$Form=new FormController();

		$Form->addChild('cansel', new ButtonController(new Delegate($this, 'cansel')));
		$Form->addChild('delete', new ButtonController(new Delegate($this, 'delete')));
		$this->addChild('myprofile_form',$Form);
		$this->setDefaultChild('myprofile_form');

		//$this->registerOnLoadListener(new Delegate($this, 'onload'));


        $mytemplate1 = 'pub/myprofile/message.html';

        $mytemplate2 = 'pub/myprofile/layout.itemlist.html';

        $mytemplate3 = 'pub/myprofile/notlogin.html';

		$this->addView('messagepage',new MyprofileView($mytemplate1,2));
		if(Session::isLogin())
			$this->setDefaultView(new MyprofileView($mytemplate2,9));
		else
			$this->setDefaultView(new MyprofileView($mytemplate3,0));

	}


	function cansel(&$controller, &$request,&$responseModel){
		$from=$responseModel->get('from');
		header('Location:'.$from);

	}

	function delete(&$controller, &$request,&$responseModel){
		$itemtypes=array('Player()','Team()','League()','Event','Article');

		switch($responseModel->get('type')){
			case 0:
				Player::delete($responseModel->get('id'));
				$item="Player profile ";
				break;
			case 1:
				Team::delete($responseModel->get('id'));
				$item="Team profile ";
				break;
			case 2:
				League::delete($responseModel->get('id'));
				$item="League/camp profile ";
				break;
			case 3:
				Event::delete($responseModel->get('id'));
				$item="Calendar event ";
				break;
			case 4:
				Article::delete($responseModel->get('id'));
				$item="Article ";
				break;
		}
		$responseModel->set('message',$item.'was deleted successfully.');
		return 'messagepage';
	}

}

class MyprofileSubscriptionsPage extends PageController {
	function MyprofileSubscriptionsPage(){
		parent::PageController();

		$Form=new FormController();

		$Form->addChild('gethistory', new ButtonController(new Delegate($this, 'gethistory')));
		$Form->addChild('cansel', new ButtonController(new Delegate($this, 'cansel')));

		$this->addChild('myprofile_form',$Form);
		$this->setDefaultChild('myprofile_form');


        $mytemplate1 = 'pub/myprofile/message.html';

        $mytemplate2 = 'pub/myprofile/subscriptions.html';

        $mytemplate3 = 'pub/myprofile/notlogin.html';

		$this->addView('messagepage',new MyprofileView($mytemplate1,2));
		if(Session::isLogin())
			$this->setDefaultView(new MyprofileView($mytemplate2,10));
		else
			$this->setDefaultView(new MyprofileView($mytemplate3,0));

	}

	function gethistory(&$controller, &$request, &$responseModel){

		/*$subscr_id=$responseModel->get('id');
		$payments=&Payment::getListForSubscription($subscr_id,$pager);*/
	}

	function cansel(&$controller, &$request, &$responseModel){

	}
}
?>
